<template>
    <div class="flex">

        <div class="flex-1 p20">
            <!-- search -->
            <el-form :inline="true">
                <el-form-item label="类型">
                    <el-select v-model="search.type" @change="getListData" placeholder="请选择">
                        <el-option label="全部" value="0"> </el-option>
                        <el-option label="公司" value="1"> </el-option>
                        <el-option label="小猴说事" value="2"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="时间">
                    <el-date-picker v-model="search.timeRange" @change="transformTimeRange" type="datetimerange" placeholder="选择时间范围"> </el-date-picker>
                </el-form-item>
            </el-form>

            <!-- 列表 -->
            <div v-for="item in listData" class="pb15 pt15 ui-border-bottom flex">
                <ui-img v-if="item.avatar" :url="item.avatar" size="50px"></ui-img>
                <span class="ui-border f-color-grey f10 flex col-center row-center" style="width:50px;height:50px">暂无图片</span>
                <div class="flex-1 ml10">
                    <div class="f10 title">
                        <span class="f-color-blue cursor-pointer" @click="goDetails(item)">{{item.post_title}}</span>
                    </div>
                    <p class="f-color-grey f12">
                        <span class="f-color-grey">[{{item.term_name}}] </span>
                        <span class="f-color-grey">{{item.create_time}}</span>
                    </p>
                </div>
            </div>

            <!-- 分页 -->
            <div class="text-center mt15">
                <el-pagination
                @current-change="getListData"
                :current-page.sync="currentPage"
                :page-size="pageSize"
                layout="prev, pager, next, jumper"
                :total="pageTotal">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        data(){
            return {
                search:{
                    type:'',
                    timeRange:[],
                    begin_time:'',
                    end_time:''
                },
                currentPage:0,
                pageSize:10,
                pageTotal: 0,
                listData:[]
            }
        },
        methods:{
            getListData(){
                // 赞
                this.$http.get('index.php?g=home&m=like&a=pc_user_like_list', {
                    params: this.search
                })
                .then(({data})=>{
                    console.log('赞、踩数据:',data)
                    if (data.code===1) {
                        // 优惠券点赞+评论点赞
                        this.listData = data.data
                        this.pageTotal = data.total
                    }
                })
            },
            goDetails(item){
                let id = item.post_id
                let routerName = ''
                
                if (item.term_name=='小猴说事') {
                    routerName = '文章详情'
                }else{
                    routerName = '彩金详情'
                }

                this.$router.push({
                    name:routerName,
                    query:{
                        id:id
                    }
                })
            },
            transformTimeRange(v){
                if (v) {
                    let str = v.split(' - ')
                    this.search.begin_time = str[0]
                    this.search.end_time = str[1]

                    this.getListData()
                }
            }
        },
        mounted(){
            this.currentPage = 1
        },
    }
</script>